﻿using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_DLL.Product.database;
using System;using ERP_RORZE_SYSTEM;
using System.Collections.Generic;
using System.Data;using ERP_RORZE_SYSTEM;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERP_RORZE_DLL.Product.DAO
{
    public class ClsQuationDAO : ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();
        public DataTable GetAllStaff()
        {
            string sql = clsConstantsFuction.ClsFuctionStaff.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllQuotation()
        {
            string sql = clsConstantsFuction.ClsFuctionQuotation.GetAll;
            return Execute.DoStoreProcedure(sql, true);

        }

        public DataTable GetAllQuotationByID(QuotationTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQuotationSP.QuotationID, SqlDbType.NVarChar, b.QuotationID)
                    
                };
            string sql = clsConstantsFuction.ClsFuctionQuotation.GetAllByID;
            return Execute.DoStoreGetByID(sql,parameter, true);

        }

        public DataTable GetAllCustumerID()
        {
            string sql = clsConstantsFuction.ClsFuctionCustomer.GetAll;
            return Execute.DoStoreProcedure(sql, true);

        }

        public void InsertQuotation(QuotationTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQuotationSP.QuotationID, SqlDbType.NVarChar, b.QuotationID),
                    CreateParameter(clsConstantsSP.ClsQuotationSP.Date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsQuotationSP.CustomerID, SqlDbType.NVarChar, b.CustomerID)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionQuotation.Insert, parameter, true);

        }

        public void DeleteQuotation(QuotationTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQuotationSP.QuotationID, SqlDbType.NVarChar, b.QuotationID)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionQuotation.Delete, parameter, true);

        }

        public void UpdateQuotation(QuotationTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQuotationSP.QuotationID, SqlDbType.NVarChar, b.QuotationID),
                    CreateParameter(clsConstantsSP.ClsQuotationSP.Date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsQuotationSP.CustomerID, SqlDbType.NVarChar, b.CustomerID)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionQuotation.Update, parameter, true);

        }

        //Quotation Machine

        public DataTable GetAllQuotationMachine()
        {
            string sql = clsConstantsFuction.ClsFuctionQmachine.GetAll;
            return Execute.DoStoreProcedure(sql, true);

        }
        public void InsertQuotationMachine(Qmachine b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQmachineSP.QuotationID, SqlDbType.NVarChar, b.QuotationID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.InputDate, SqlDbType.DateTime, b.InputDate),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.MPartNo, SqlDbType.NVarChar, b.MPartNo),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.Note, SqlDbType.NVarChar, b.Note)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionQmachine.Insert, parameter, true);
        }

        public void UpdateQuotationMachine(Qmachine b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQmachineSP.RecordNo, SqlDbType.Int, b.RecordNo),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.QuotationID, SqlDbType.NVarChar, b.QuotationID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.InputDate, SqlDbType.DateTime, b.InputDate),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.MPartNo, SqlDbType.NVarChar, b.MPartNo),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.ProTime, SqlDbType.Float, b.ProTime),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsQmachineSP.Note, SqlDbType.NVarChar, b.Note)
                    
                };
            Execute.DoUpdate(clsConstantsFuction.ClsFuctionQmachine.Update, parameter, true);
        }

        public void DeleteQuotationMachine(Qmachine b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQmachineSP.RecordNo, SqlDbType.Int, b.RecordNo)
                    
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionQmachine.Delete, parameter, true);
        }

        //Quotation Material

        public DataTable GetAllQuotationMaterial()
        {
            string sql = clsConstantsFuction.ClsFuctionQMaterial.GetAll;
            return Execute.DoStoreProcedure(sql, true);

        }

        public void InsertQuotationMaterial(QMaterial b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.QuotationID, SqlDbType.NVarChar, b.QuotationID),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MPartNo, SqlDbType.NVarChar, b.MPartNo),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MaterialID, SqlDbType.NVarChar, b.MaterialID),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MPartNo, SqlDbType.NVarChar, b.MPartNo),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MaterialType, SqlDbType.NVarChar, b.MaterialType),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MaterialPrice, SqlDbType.Money, b.MaterialPrice),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Shape, SqlDbType.NVarChar, b.Shape),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Thickness, SqlDbType.Float, b.Thickness),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Length, SqlDbType.Float, b.Length),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Width, SqlDbType.Float, b.Width),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Price, SqlDbType.Money, b.Price),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Note, SqlDbType.NVarChar, b.Note)
                    
                };
            Execute.DoInsert(clsConstantsFuction.ClsFuctionQMaterial.Insert, parameter, true);
        }

        public void UpdateQotationMaterial(QMaterial b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.RecordNo, SqlDbType.Int, b.RecordNo),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.QuotationID, SqlDbType.NVarChar, b.QuotationID),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MPartNo, SqlDbType.NVarChar, b.MPartNo),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MaterialID, SqlDbType.NVarChar, b.MaterialID),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MPartNo, SqlDbType.NVarChar, b.MPartNo),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MaterialType, SqlDbType.NVarChar, b.MaterialType),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.MaterialPrice, SqlDbType.Money, b.MaterialPrice),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Shape, SqlDbType.NVarChar, b.Shape),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Thickness, SqlDbType.Float, b.Thickness),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Length, SqlDbType.Float, b.Length),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Width, SqlDbType.Float, b.Width),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Price, SqlDbType.Money, b.Price),
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.Note, SqlDbType.NVarChar, b.Note)
                    
                };
            Execute.DoUpdate(clsConstantsFuction.ClsFuctionQMaterial.Update, parameter, true);
        }

        public void DeleteQuotationMaterial(QMaterial b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsQMaterialSP.RecordNo, SqlDbType.Int, b.RecordNo)
                    
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionQMaterial.Delete, parameter, true);
        }
    }
}
